﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ApiTemplateGenerate.TemplateTsAxios
{
    /// <summary>
    /// TS API方法模版
    /// 
    /// import service from '../../config'
    /// import link from '../../link'
    /// import* as common from '../../commonArgument'
    /// let ApiUrl = link.OAServiceX.APIService
    /// /**
    ///  * 分页获取数据
    ///  * @param pageIndex 当前页码
    ///  * @param pageSize 页大小
    ///  * @param startTime 开始时间
    ///  * @param endTime 结束时间
    ///  * @returns
    ///  */
    /// export const GetPageList = async(pageIndex: number, pageSize: number, startTime: number, endTime: number) => {
    ///   let responseData: any = await service({
    ///     url: ApiUrl + '/api/VersionInfo/GetPageList',
    ///     method: 'get',
    ///     params: { pageIndex: pageIndex, pageSize: pageSize, startTime: startTime, endTime: endTime }
    ///     })
    ///   let responseDataReturn: PageList<oa_versioninfo> = responseData
    ///   return responseDataReturn
    /// }
    /// </summary>
    public class TemplateMethod
    {

        public static string Template = @"
@{
   var tempString = '@';
}
import service from '@tempString/api/config'
import link from '@tempString/api/link'
let ApiUrl = link.OA3Api.APIService
@foreach (var item in Model){
    if(!string.IsNullOrEmpty(@item.Describes)){<text>@item.Describes</text>}else{}
<text></text>
<text>export const @item.MethodName = async (@item.ParameterString) => {</text>
  <text>  let responseData : any = await service({</text>
    <text>    url: ApiUrl + '@item.ApiUrl',</text>
    <text>    method: '@item.RequestMethod',;</text>
 if(!item.IsNullParam){
         if(item.IsParams){
    <text>    params: @item.Params,;</text>
         }
         if(item.IsData){
    <text>    data: @item.Data,;</text>
         }
}
if(item.IsImport){
    <text>    headers: { 'Content-Type': 'multipart/form-data' },;</text>
    <text>    data: file,;</text>
}
if(item.IsDownload){
    <text>    responseType: 'blob'</text>
}
  <text>;  })</text>
  <text>  let responseDataReturn: </text><text>@item.ReturnValue = responseData
  return responseDataReturn</text>
<text>};</text>
}
";
    }
}
